package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2024-08-25
 */
@Api(tags = "客户端-互动问答相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 新增问题
     *
     * @param questionFormDTO
     */
    @PostMapping
    @ApiOperation("新增问题")
    public void saveQuestion(@RequestBody QuestionFormDTO questionFormDTO) {
        questionService.saveQuestion(questionFormDTO);

    }

    /**
     * 分页查询问题和回复
     *
     * @param questionPage
     */
    @GetMapping("/page")
    @ApiOperation("分页查询问题和回复")
    public PageDTO<QuestionVO> queryPageQuestion(QuestionPageQuery questionPage) {
        return questionService.queryPageQuestion(questionPage);

    }

    /**
     * 根据id查询问题详情
     *
     * @param id
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO queryQuestionById(@PathVariable Long id) {
        return questionService.queryQuestionById(id);

    }

    /**
     * 删除问题  实战 1
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除问题")
    public void deleteQuestion(@PathVariable Long id) {
        questionService.deleteQuestion(id);

    }

    /**
     * 编辑互动问题  实战 2
     *
     * @param questionFormDTO
     */
    @PutMapping("/{id}")
    @ApiOperation("修改问题")
    public void putQuestion(@PathVariable Long id, @RequestBody QuestionFormDTO questionFormDTO) {
        questionService.putQuestion(id, questionFormDTO);

    }

}
